<template>
  <div class="bannerContainer">
    <img :src="images[currentIndex]" class="bannerImage" />

    <button v-if="currentIndex > 0" @click="prev" class="prev">‹</button>

    <button v-if="currentIndex < images.length - 1" @click="next" class="next">
      ›
    </button>

    <div class="dots">
      <span
        v-for="(image, index) in images"
        :key="image"
        @click="switchImage(index)"
        :class="{ active: index == currentIndex }"
        class="dot"
      ></span>
    </div>
  </div>
</template>

<script>
import img1 from "./assets/img/fj1.png";
import img2 from "./assets/img/fj2.png";
import img3 from "./assets/img/fj3.png";
import img4 from "./assets/img/fj4.png";
export default {
  data() {
    return {
      images: [img1, img2, img3, img4],
      currentIndex: 0,
    };
  },
  methods: {
    next() {
      this.currentIndex = (this.currentIndex + 1) % this.images.length;
    },
    prev() {
      this.currentIndex =
        (this.currentIndex - 1 + this.images.length) % this.images.length;
    },
    switchImage(index) {
      this.currentIndex = index;
    },
  },
};
</script>

<style scoped>
.bannerContainer {
  position: relative;
  width: 600px;
  height: 400px;
  margin: 50px auto;
}

.bannerImage {
  width: 600px;
  height: 400px;
}

button {
  position: absolute;
  width: 30px;
  height: 50px;
  top: 50%;
  margin-top: -25px;
  background-color: gray;
  color: white;
  border: none;
  cursor: pointer;
  font-size: 25px;
  line-height: 50px;
}

button:hover {
  background-color: grey;
}

.prev {
  left: 0;
}

.next {
  right: 0;
}

.dots {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  gap: 10px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
}

.dot.active {
  background-color: white;
}

.dot:hover {
  background-color: rgba(255, 255, 255, 0.8);
}
</style>